package com.cdu.practicaltraining.sys.mapper;

import com.cdu.practicaltraining.pojo.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RoleMapper {
    int add(Role role) throws Exception;

    @Select("select role_name from t_roles where role_name = #{role_name}")
    Role findByName(String role_name) throws Exception;

    @Select("select id, role_name, description, state, ucreate_by, create_time, uupdate_by, update_time,version " +
            "from t_roles where is_deleted=0")
    List<Role> roles() throws Exception;

    @Select("select id, role_name, description, state, ucreate_by, create_time, uupdate_by, update_time,version " +
            "from t_roles where id=#{id} and is_deleted=0")
    Role findById(long id) throws Exception;

    int updateRole(Role role) throws Exception;

    @Update("update t_roles set is_deleted = 1, version=version+1 where id=#{id}")
    int deleteRole(long id) throws Exception;
}
